<template>
  <div class="history-hot">
    <div class="hishot-box" v-show="isShowHistory">
      <div class="head">
        <h4>历史记录</h4>
        <van-icon name="delete-o" @click="delHistory" />
      </div>
      <div class="budy">
        <van-tag
          plain
          type="primary"
          color="#666"
          v-for="(item, index) in historyKeywordList"
          :key="index"
          @click="tagClick(item)"
          >{{ item }}</van-tag
        >
      </div>
    </div>
    <div class="hishot-box">
      <div class="head">
        <h4>热门搜索</h4>
      </div>
      <div class="budy">
        <van-tag
          plain
          color="#666"
          :type="item.is_hot ? 'danger' : 'primary'"
          v-for="(item, index) in hotKeywordList"
          :key="index"
          @click="tagClick(item.keyword)"
          >{{ item.keyword }}</van-tag
        >
      </div>
    </div>
  </div>
</template>

<script>
import {ClearHistoryAPI} from '@/request/api.js'
export default {
  props: ["historyKeywordList", "hotKeywordList"],
  data() {
    return {
      isShowHistory: true
    };
  },
  methods: {
    tagClick(val) {
      this.$emit('tagClick', val);
    },
    delHistory() {
      ClearHistoryAPI()
        .then(res => {
          console.log('ClearHistoryAPI', res);
        })
      this.$toast.success('删除成功');
      setTimeout(() => {
        this.isShowHistory = false
      }, 500)
    }
  }
};
</script>
 
<style lang = "less" scoped>
.hishot-box {
  background-color: #fff;
  padding: 0.08rem;
  margin-bottom: 0.2rem;

  .head {
    font-size: 0.18rem;
    display: flex;
    justify-content: space-between;
  }

  .van-tag {
    margin-bottom: 0.05rem;
    margin-right: 0.05rem;
    margin-top: 0.1rem;
  }

  .van-tag--danger.van-tag--plain {
    color: #ee0a24 !important;
    border-color: #ee0a24 !important;
  }
}
</style>